package com.example.demo.controller;

import com.example.demo.entry.User;
import com.example.demo.entry.loginUser;
import com.example.demo.utils.JwtUtils;
import com.example.demo.utils.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class loginUsetController {
    @PostMapping("/user/login")
    public Result login(@RequestBody loginUser loginuser)
    {
        String token = JwtUtils.generateToken(loginuser.username);
        System.out.println("=============>"+token);
        return Result.ok().data("token",token);
    }
    @GetMapping("/user/info")
    public Result info(String token)
    {
        System.out.println("=============>"+token);
        String username = JwtUtils.getClaimsByToken(token).getSubject();
        String url = "https://cn.bing.com/images/search?q=T%E5%A4%B4%E5%83%8F&FORM=IQFRBA&id=FF6A46F30FA6E9F5C0CBEA4F746D62D27379764D";
        return Result.ok().data("name",username).data("avatar",url);
    }
    @PostMapping("/user/logout")
    public Result logout()
    {
        return Result.ok();
    }
}
